import os
import os.path
import gzip

from dgraph.json2rdf import reformat


def read_gz_file(path):
    if os.path.exists(path):
        f2 = open(path[:-16] + 's2rdfs/' + path[-16:-3] + '.rdf', 'w', encoding='utf-8')
        with gzip.open(path, 'r') as pf:
            for line in pf:
                reformat(line, f2)
    else:
        print('the path [{}] is not exist!'.format(path))


if __name__ == '__main__':
    for i in range(2, 3):
        if i < 10:
            i = '00' + str(i)
        elif 10 <= i < 100:
            i = '0' + str(i)
        else:
            i = str(i)
        rel_path = '/mnt/liutao_download/s2-corpus-' + i + '.gz'
        print(rel_path)
        print(rel_path[:-16] + 's2rdfs/' + rel_path[-16:-3] + '.rdf')
        # read_gz_file(rel_path)
